package com.axon.brasil.formatters {
  
  import mx.formatters.Formatter;
  import mx.utils.StringUtil;

  public class NcmFormatter extends Formatter {
    
    public function NcmFormatter() {
      super();
    }
    
		override public function format(value: Object): String
		{
			if (error)
				error = null;
				
			var strBruto: String = value as String;
			var result  : String = "";
			var size    : Number;
			var cursor  : Number = 0;
			
			strBruto = StringUtil.trim(strBruto);

			while (strBruto.indexOf(".") != -1) {
				strBruto = strBruto.replace(".","");
			}
			
			size = strBruto.length;
			
			for (var i: Number = (size - 1); i >= 0; i--) {
				cursor++;
				if ((cursor == 3) || (cursor == 6)) {
					result = "." + result;
				}
				result = strBruto.charAt(i) + result;
			}
			return result;
		}

  }
}